/// \file		WnBaseIOService.h
/// \brief		WIND基础IO服务类的声明文件
/// \author		xuefeng
/// \version	1.0
/// \date		2011-07-20
/// \history	2011-07-20 新建

#pragma once
#include <boost/asio/io_service.hpp>

/// \brief WIND基础IO服务类的声明文件
class WnBaseIOService
{
public:
	/// \brief 启动服务
	void StartService(unsigned short usThreadCount);

	/// \brief 停止服务
	void StopService();

	/// \brief 获取IO异步处理服务
	boost::asio::io_service& GetIOService() { return m_oIoService; }

public:
	/// \brief 构造函数
	WnBaseIOService(void);

	/// \brief 析构函数
	virtual ~WnBaseIOService(void);

	/// \brief 获取与CPU数匹配的线程数
	unsigned short GetThreadCount();

	/// \brief IO异步处理服务线程函数
	void ThreadsFunc();

private:
	/// \brief IO异步处理服务
	boost::asio::io_service m_oIoService;

	/// \brief IO工作状态
	boost::shared_ptr<boost::asio::io_service::work> m_apWork;

	/// \brief IO异步处理服务线程组
	boost::thread_group m_oIoServiceThreads;

	/// \brief 停止标志
	bool m_blStop;

  boost::mutex m_mtx_log;
};
